<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>clientTop&Left</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }

        .box{
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
        }
    </style>
</head>
<body>
    <div class="box"></div>

    <script type="text/javascript">
        /* 
        elem.clientTop/Left 返回元素上左边框的宽度
        */    
        var box = document.querySelector(".box");


        console.log("box.clientTop", box.clientTop, "\nbox.clientLeft", box.clientLeft); // 0 0
        
        box.style.borderTop = "30px solid #00f";
        console.log("box.clientTop", box.clientTop, "\nbox.clientLeft", box.clientLeft); // 30 0
        
        box.style.borderLeft = "20px solid #00f";
        console.log("box.clientTop", box.clientTop, "\nbox.clientLeft", box.clientLeft); // 30 20

        box.clientTop = 60;
        console.log("设置 clientTop 60");
        console.log("box.clientTop", box.clientTop, "\nbox.clientLeft", box.clientLeft); // 30 20
        
        box.style.borderTopWidth = "30.633px";
        console.log("设置borderTop 为小数");
        console.log("box.clientTop", box.clientTop, "\nbox.clientLeft", box.clientLeft); // 31 20
    </script>
</body>
</html>